﻿using System;
using System.Collections.Generic;
using System.Text;

namespace curbside.Web.UI.WebControls
{
    /// <summary>
    /// Accordion 控件
    /// </summary>
    public class Accordion : System.Web.UI.WebControls.Panel
    {
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            base.Render(writer);
            string jsEvent = "$(function(){var jobj = $('#" + this.ClientID + "');";
            jsEvent += "jobj.accordion({ event: '" + AccordionEvent.ToString() + "' });";
            if (ContentHeight > 0)
            {
                jsEvent += "jobj.find('.ui-accordion-content').height(" + ContentHeight + ");";
            }
            jsEvent += "});";
            helper.AddStartupScript(ClientID, jsEvent, this.Page);
        }

        /// <summary>
        /// 设置或获取 Accordion切换方式
        /// </summary>
        public AccordionEvent AccordionEvent
        {
            get
            {
                object obj = this.ViewState["AccordionEvent"];
                if (obj == null) return AccordionEvent.click;
                return (AccordionEvent)obj;
            }
            set { this.ViewState["AccordionEvent"] = value; }
        }

        /// <summary>
        /// 设置或获取 默认选择的Accordion页索引
        /// </summary>
        public int SelectIndex
        {
            get
            {
                object obj = this.ViewState["SelectIndex"];
                if (obj == null) return 0;
                return (int)obj;
            }
            set { this.ViewState["SelectIndex"] = value; }
        }

        /// <summary>
        /// 设置或获取 内容div高度
        /// </summary>
        public int ContentHeight
        {
            get
            {
                object obj = this.ViewState["ContentHeight"];
                if (obj == null) return 0;
                return (int)obj;
            }
            set { this.ViewState["ContentHeight"] = value; }
        }
    }

    /// <summary>
    /// 定义AccordionEvent切换方式枚举
    /// </summary>
    public enum AccordionEvent
    {
        mouseover,
        click
    }
}
